package cn.sh.ideal.web.view.display.distributead.ddatabase.monitor.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import cn.sh.ideal.web.view.display.distributead.ddatabase.monitor.entity.DistributedDatabaseMonitorEntity;
import cn.sh.ideal.web.view.display.message.middleware.monitor.entity.MessageMiddlewareMonitorEntity;

@Controller
@RequestMapping(value = "/data")
@PropertySource(value = { "classpath:jdbc.properties" })
public class DistributedDatabaseMonitorDataController {

	@Bean
	public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
		return new PropertySourcesPlaceholderConfigurer();
	}

	private RestTemplate rs = new RestTemplate();

	@Value("${server_address}")
	private String serverAddress;

	/**
	 * 获取原系统主机信息
	 * @param paramter
	 * @return
	 */
	@RequestMapping(value = "/selectDistributedDatabaseMonitorInfo", method = RequestMethod.POST)
	@ResponseBody
	public String getUserInfo(@RequestBody DistributedDatabaseMonitorEntity paramter) {

		Integer size = paramter.getSize();
		Integer page = paramter.getPage();
		String hostName = paramter.getHostName();
		String systemName = paramter.getSystemName();

		String url = serverAddress+"/selectDistributedDatabaseMonitorInfo?size="
				+ size + "&page=" + page  + "&hostName=" + hostName + "&systemName=" + systemName ;
		HttpHeaders headers = new HttpHeaders();
		MediaType type = MediaType
				.parseMediaType("application/json;charset=UTF-8");
		headers.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), headers);

		ResponseEntity<String> exchange = rs.exchange(url, HttpMethod.GET,
				entity, String.class);

		String reult = exchange.getBody();
		return reult;
}
}